<?
if(!defined ('U_MOD'))
{
	echo"<meta http-equiv='refresh' content='0;url=/index.php'>";
	exit;
}

$refferUrl=getRefferUrl($_SERVER['HTTP_REFERER'], $portal_url);

if (isset($act) && is_numeric($act))
{
	if ($act==1 && isset($nid))
	{
		if(mysql_query("DELETE FROM ".$PortalPref.$amk." WHERE nav_id='".$nid."'"))
		{
			mysql_query("DELETE FROM ".$PortalPref.$amk." WHERE nav_parent_id='".$nid."'");
			print '<p align="center">'._OPERATION_SUCCESS_.'</p>';
		}else
			print '<p align="center">'.BAD_SQL_.'</p>';
	}

	if ($act==2 && isset($nid))
	{
		if(mysql_query("UPDATE ".$PortalPref.$amk." SET nav_activity='1' WHERE nav_id='".$nid."'"))
			print '<p align="center">'._OPERATION_SUCCESS_.'</p>';
		else
			print '<p align="center">'.BAD_SQL_.'</p>';
	}

	if ($act==3 && isset($nid))
	{
		if(mysql_query("UPDATE ".$PortalPref.$amk." SET nav_activity='0' WHERE nav_id='".$nid."'"))
			print '<p align="center">'._OPERATION_SUCCESS_.'</p>';
		else
			print '<p align="center">'.BAD_SQL_.'</p>';
	}

	if ($act==4 && isset($nid))
	{
		$queryGetOrder=mysql_query("SELECT * FROM ".$PortalPref.$amk." WHERE nav_id='".$nid."'");
		if(mysql_num_rows($queryGetOrder)==1)
		{
			$resultGetOrder=mysql_fetch_assoc($queryGetOrder);
			$newOrderForItem=$resultGetOrder['nav_order']+1;

			if($newOrderForItem>=0)
			{
				$querySetNewOrderForOther="UPDATE ".$PortalPref.$amk." SET nav_order='".$resultGetOrder['nav_order']."' WHERE nav_parent_id='".$resultGetOrder['nav_parent_id']."' AND nav_order='".$newOrderForItem."'";
				$querySetNewOrderForItem="UPDATE ".$PortalPref.$amk." SET nav_order='".$newOrderForItem."' WHERE nav_id='".$nid."'";
				if(mysql_query($querySetNewOrderForOther))
				{
					if(mysql_query($querySetNewOrderForItem))
						print '<p align="center">'._OPERATION_SUCCESS_.'</p>';
					else
					{
						mysql_query("UPDATE ".$PortalPref.$amk." SET nav_order='".$newOrderForItem."' WHERE nav_parent_id='".$resultGetOrder['nav_parent_id']."' AND nav_order='".$resultGetOrder['nav_order']."'");
						print '<p align="center">'.BAD_SQL_.'</p>';
					}
				}
			}else
				print '<p align="center">'._BAD_NEW_ORDER_.'</p>';

		}else
			print '<p align="center">'._NO_NAVIGATION_FOR_EDITE_.'</p>';
	}

	if ($act==5 && isset($nid))
	{
		$queryGetOrder=mysql_query("SELECT * FROM ".$PortalPref.$amk." WHERE nav_id='".$nid."'");
		if(mysql_num_rows($queryGetOrder)==1)
		{
			$resultGetOrder=mysql_fetch_assoc($queryGetOrder);
			$newOrderForItem=$resultGetOrder['nav_order']-1;

			if($newOrderForItem>=0)
			{
				$querySetNewOrderForOther="UPDATE ".$PortalPref.$amk." SET nav_order='".$resultGetOrder['nav_order']."' WHERE nav_parent_id='".$resultGetOrder['nav_parent_id']."' AND nav_order='".$newOrderForItem."'";
				$querySetNewOrderForItem="UPDATE ".$PortalPref.$amk." SET nav_order='".$newOrderForItem."' WHERE nav_id='".$nid."'";
				if(mysql_query($querySetNewOrderForOther))
				{
					if(mysql_query($querySetNewOrderForItem))
						print '<p align="center">'._OPERATION_SUCCESS_.'</p>';
					else
					{
						mysql_query("UPDATE ".$PortalPref.$amk." SET nav_order='".$newOrderForItem."' WHERE nav_parent_id='".$resultGetOrder['nav_parent_id']."' AND nav_order='".$resultGetOrder['nav_order']."'");
						print '<p align="center">'.BAD_SQL_.'</p>';
					}
				}
			}else
				print '<p align="center">'._BAD_NEW_ORDER_.'</p>';

		}else
			print '<p align="center">'._NO_NAVIGATION_FOR_EDITE_.'</p>';
	}

	if ($act==6 && isset($nid))
	{
		$queryGetMaxOrder=mysql_query("SELECT MAX(nav_footer) AS max FROM ".$PortalPref.$amk);
		$resultGetMaxOrder=mysql_fetch_assoc($queryGetMaxOrder);
		if(is_null($resultGetMaxOrder['max']))
			$orderFooter=1;
		else
			$orderFooter=$resultGetMaxOrder['max']+1;

		if(mysql_query("UPDATE ".$PortalPref.$amk." SET nav_footer='".$orderFooter."' WHERE nav_id='".$nid."'"))
			print '<p align="center">'._OPERATION_SUCCESS_.'</p>';
		else
			print '<p align="center">'.BAD_SQL_.'</p>';
	}

	if ($act==7 && isset($nid))
	{
		$queryGetFooterOrder=mysql_query("SELECT nav_footer FROM ".$PortalPref.$amk." WHERE nav_id='".$nid."'");
		if(mysql_num_rows($queryGetFooterOrder)!=1)
			print '<p align="center">'._NO_NAVIGATION_FOR_EDITE_.'</p>';
		else
		{
			$resultGetFooterOrder=mysql_fetch_assoc($queryGetFooterOrder);

			if(mysql_query("UPDATE ".$PortalPref.$amk." SET nav_footer='0' WHERE nav_id='".$nid."'"))
			{
				mysql_query("UPDATE ".$PortalPref.$amk." SET nav_footer=nav_footer-1 WHERE nav_footer > '".$resultGetFooterOrder['nav_footer']."'");
				print '<p align="center">'._OPERATION_SUCCESS_.'</p>';
			}
			else
				print '<p align="center">'.BAD_SQL_.'</p>';
		}
	}

	if ($act==8 && isset($nid))
	{
		$queryGetOrder=mysql_query("SELECT * FROM ".$PortalPref.$amk." WHERE nav_id='".$nid."'");
		if(mysql_num_rows($queryGetOrder)==1)
		{
			$resultGetOrder=mysql_fetch_assoc($queryGetOrder);
			$newOrderForItem=$resultGetOrder['nav_footer']+1;

			if($newOrderForItem>=0)
			{
				$querySetNewOrderForOther="UPDATE ".$PortalPref.$amk." SET nav_footer='".$resultGetOrder['nav_footer']."' WHERE nav_footer='".$newOrderForItem."'";
				$querySetNewOrderForItem="UPDATE ".$PortalPref.$amk." SET nav_footer='".$newOrderForItem."' WHERE nav_id='".$nid."'";
				if(mysql_query($querySetNewOrderForOther))
				{
					if(mysql_query($querySetNewOrderForItem))
						print '<p align="center">'._OPERATION_SUCCESS_.'</p>';
					else
					{
						mysql_query("UPDATE ".$PortalPref.$amk." SET nav_footer='".$newOrderForItem."' WHERE nav_footer='".$resultGetOrder['nav_footer']."'");
						print '<p align="center">'.BAD_SQL_.'</p>';
					}
				}
			}else
				print '<p align="center">'._BAD_NEW_ORDER_.'</p>';

		}else
			print '<p align="center">'._NO_NAVIGATION_FOR_EDITE_.'</p>';
	}

	if ($act==9 && isset($nid))
	{
		$queryGetOrder=mysql_query("SELECT * FROM ".$PortalPref.$amk." WHERE nav_id='".$nid."'");
		if(mysql_num_rows($queryGetOrder)==1)
		{
			$resultGetOrder=mysql_fetch_assoc($queryGetOrder);
			$newOrderForItem=$resultGetOrder['nav_footer']-1;

			if($newOrderForItem>=0)
			{
				$querySetNewOrderForOther="UPDATE ".$PortalPref.$amk." SET nav_footer='".$resultGetOrder['nav_footer']."' WHERE nav_footer='".$newOrderForItem."'";
				$querySetNewOrderForItem="UPDATE ".$PortalPref.$amk." SET nav_footer='".$newOrderForItem."' WHERE nav_id='".$nid."'";
				if(mysql_query($querySetNewOrderForOther))
				{
					if(mysql_query($querySetNewOrderForItem))
						print '<p align="center">'._OPERATION_SUCCESS_.'</p>';
					else
					{
						mysql_query("UPDATE ".$PortalPref.$amk." SET nav_footer='".$newOrderForItem."' WHERE nav_footer='".$resultGetOrder['nav_footer']."'");
						print '<p align="center">'.BAD_SQL_.'</p>';
					}
				}
			}else
				print '<p align="center">'._BAD_NEW_ORDER_.'</p>';

		}else
			print '<p align="center">'._NO_NAVIGATION_FOR_EDITE_.'</p>';
	}
}

echo"<meta http-equiv='refresh' content='0;url=".$refferUrl."'>";
?>